home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / manual / examples / testopt.c < prev   
C/C++ Source or Header  |  1994-02-16  |  962b  |  51 lines

  1. /*@group*/
  2. #include <unistd.h>
  3. #include <stdio.h>
  4.  
  5. int 
  6. main (int argc, char **argv)
  7. {
  8.   int aflag = 0;
  9.   int bflag = 0;
  10.   char *cvalue = NULL;
  11.   int index;
  12.   int c;
  13.  
  14.   opterr = 0;
  15. /*@end group*/
  16.  
  17. /*@group*/
  18.   while ((c = getopt (argc, argv, "abc:")) != -1)
  19.     switch (c)
  20.       {
  21.       case 'a':
  22.         aflag = 1;
  23.         break;
  24.       case 'b':
  25.         bflag = 1;
  26.         break;
  27.       case 'c':
  28.         cvalue = optarg;
  29.         break;
  30.       case '?':
  31.         if (isprint (optopt))
  32.           fprintf (stderr, "Unknown option `-%c'.\n", optopt);
  33.         else
  34.           fprintf (stderr,
  35.                    "Unknown option character `\\x%x'.\n",
  36.                    optopt);
  37.         return 1;
  38.       default:
  39.         abort ();
  40.       }
  41. /*@end group*/
  42.  
  43. /*@group*/
  44.   printf ("aflag = %d, bflag = %d, cvalue = %s\n", aflag, bflag, cvalue);
  45.  
  46.   for (index = optind; index < argc; index++)
  47.     printf ("Non-option argument %s\n", argv[index]);
  48.   return 0;
  49. }
  50. /*@end group*/
  51.